const computedBehavior = require('miniprogram-computed')
const app = getApp()
Component({
  behaviors: [computedBehavior],
  data: {
    userinfo: null
  },
  computed: {
    memberType () {
      return this.data.userinfo
            ? this.data.userinfo.AgentInfo.SalerType|| this.data.userinfo.AgentInfo.AgentType
            : ''
    },
    name () {
      return this.data.userinfo ? this.data.userinfo.AgentInfo.AgentName : ''
    },
    tel() {
      return this.data.userinfo ? this.data.userinfo.AgentInfo.Phone : ''
    },
    idnum () {
      return this.data.userinfo ? this.data.userinfo.AgentInfo.CardId || '暂无' : '暂无'
    },
    bankcardnum() {
      return this.data.userinfo ? this.data.userinfo.AgentInfo.BankCard || '暂无' : '暂无'
    },
    bankname() {
      return this.data.userinfo ? this.data.userinfo.AgentInfo.BankName || '暂无' : '暂无'
    },
    subbankname() {
      return this.data.userinfo ? this.data.userinfo.AgentInfo.BranchBankName || '暂无' : '暂无'
    }
  },
  methods: {
    onLoad(options) {
    },
    onReady() { },
    onShow() {
      app.updateUserInfo({
        force: true
      }).then(res => {
        console.log(res)
        this.setData({
          userinfo: res
        })
      }).catch(err => {
        console.log(err)
        if (err === '用户未注册') {
          wx.showModal({
            title: '对不起',
            content: '您还未注册',
            showCancel: false,
            success: r => {
              if (r.confirm) {
                wx.redirectTo({
                  url: '/pages/index/index'
                })
              }
            }
          })
        }
      })
    },
    onShareAppMessage() {
      return app.shareInfo
    }
  }
})